<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "product".
 *
 * @property int $id
 * @property string $name 产品名称
 * @property string $spu SPU
 * @property int|null $template_id 产品模板ID
 * @property string|null $template_no 产品版号
 * @property string|null $product_type 产品详细分类
 * @property int $is_customize 是否定制产品：1是,0否
 * @property string $magento_template_id 模板ID(网站的模板)
 * @property string $brand 品牌
 * @property string|null $osku 旧版sku
 * @property string|null $main_sku 主SKU
 * @property int|null $oid 旧版产品ID
 * @property string $gender 款式（男、女、通用）
 * @property int $is_clearance 是否清仓
 * @property int $support_stock 是否支持库存
 * @property string|null $short_description 产品默认英文短小简介
 * @property string|null $description 产品默认英文简介
 * @property string|null $copyright 版权
 * @property int $uid 创建人
 * @property int $created_at 创建时间
 * @property int $updated_at 修改时间
 * @property string|null $fids 附件/图片
 * @property string|null $plating_color 电镀颜色-网站筛选项
 * @property string|null $style 对应product tag 表 id
 * @property string|null $occasion 对应product_tag 表 id
 * @property string|null $recipient 对应product_tag 表 id
 * @property string|null $gtin 谷歌跟踪标记，全网唯一
 * @property int|null $img_change 标记图片是否改变，只有当图片修改后才同步图片给magento
 * @property string|null $fids_pic 实拍图
 * @property string|null $fids_zip SSY压缩包
 * @property int|null $status 主站上架状态
 * @property int|null $review_num 评论数
 * @property string|null $product_set_number 套装编码
 * @property int|null $qty_ordered 发货数量
 */
class Product extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'product';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'spu', 'magento_template_id', 'brand', 'gender', 'uid', 'created_at', 'updated_at'], 'required'],
            [['template_id', 'is_customize', 'oid', 'is_clearance', 'support_stock', 'uid', 'created_at', 'updated_at', 'img_change', 'status', 'review_num', 'qty_ordered'], 'integer'],
            [['gender', 'short_description', 'description'], 'string'],
            [['name', 'template_no', 'product_type', 'fids', 'style', 'occasion', 'recipient', 'gtin', 'fids_pic', 'fids_zip'], 'string', 'max' => 255],
            [['spu', 'magento_template_id', 'brand', 'osku', 'main_sku', 'copyright', 'product_set_number'], 'string', 'max' => 50],
            [['plating_color'], 'string', 'max' => 60],
            [['spu'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id'                  => 'ID',
            'name'                => 'Name',
            'spu'                 => 'Spu',
            'template_id'         => 'Template ID',
            'template_no'         => 'Template No',
            'product_type'        => 'Product Type',
            'is_customize'        => 'Is Customize',
            'magento_template_id' => 'Magento Template ID',
            'brand'               => 'Brand',
            'osku'                => 'Osku',
            'main_sku'            => 'Main Sku',
            'oid'                 => 'Oid',
            'gender'              => 'Gender',
            'is_clearance'        => 'Is Clearance',
            'support_stock'       => 'Support Stock',
            'short_description'   => 'Short Description',
            'description'         => 'Description',
            'copyright'           => 'Copyright',
            'uid'                 => 'Uid',
            'created_at'          => 'Created At',
            'updated_at'          => 'Updated At',
            'fids'                => 'Fids',
            'plating_color'       => 'Plating Color',
            'style'               => 'Style',
            'occasion'            => 'Occasion',
            'recipient'           => 'Recipient',
            'gtin'                => 'Gtin',
            'img_change'          => 'Img Change',
            'fids_pic'            => 'Fids Pic',
            'fids_zip'            => 'Fids Zip',
            'status'              => 'Status',
            'review_num'          => 'Review Num',
            'product_set_number'  => 'Product Set Number',
            'qty_ordered'         => 'Qty Ordered',
        ];
    }

    /**
     * {@inheritdoc}
     * @return ModelQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new ModelQuery(get_called_class());
    }


    /**
     * Notes:
     * User: Administrator
     * DateTime: 2021/4/13 9:26
     * @return array|\yii\db\ActiveRecord|null
     */
    public function getOrderItem()
    {
        return $this->hasMany(Orderitem::class, ['product_id'=>'id']);
    }
}
